home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / misc / ispell-3.001 / ispell-3~ / ispell-3.1 / iwhich < prev    next >
Text File  |  1995-10-12  |  1KB  |  78 lines

  1. : Use /bin/sh
  2. #
  3. # $Id: iwhich,v 1.2 1995/10/11 02:31:58 geoff Exp $
  4. #
  5. # Report which version of a command is in use.  This version of
  6. # "which" doesn't handle shell aliases, but it makes up for that with
  7. # the "-a" (report all copies) switch and the fact that it returns a
  8. # nonzero shell status if the command isn't found.
  9. #
  10. USAGE='Usage:  which [-a] command[s]'
  11. #
  12. # For each command, the full pathname of the version that will be
  13. # selected from $PATH is reported.  If the -a switch is given,
  14. # versions in $PATH that are overridden by earlier $PATH entries will
  15. # also be reported.  The exit status is nonzero if none of the
  16. # commands are found anywhere in $PATH.
  17. #
  18. # $Log: iwhich,v $
  19. # Revision 1.2  1995/10/11  02:31:58  geoff
  20. # Work around a buggy version of Ultrix test
  21. #
  22. # Revision 1.1  1995/01/15  00:13:54  geoff
  23. # Initial revision
  24. #
  25. #
  26. opath=$PATH
  27. PATH=/bin:/usr/bin
  28. all=no
  29. while [ $# -gt 0 ]
  30. do
  31.     case "$1" in
  32.     -a)
  33.         all=yes
  34.         shift
  35.         ;;
  36.     -*)
  37.         echo "$USAGE" 1>&2
  38.         exit 2
  39.         ;;
  40.     *)
  41.         break
  42.         ;;
  43.     esac
  44. done
  45. case $# in
  46.     0)
  47.     echo "$USAGE" 1>&2
  48.     exit 2
  49.     ;;
  50. esac
  51. opath=`echo "$opath" | sed 's/^:/.:/
  52.               s/::/:.:/g
  53.               s/:$/:./
  54.               s/:/ /g'`
  55. found=false
  56. for file
  57. do
  58.     for i in $opath
  59.     do
  60.     if [ \( -x $i/$file \) -a \( ! -d $i/$file \) ]
  61.     then
  62.         echo $i/$file
  63.         found=true
  64.         case "$all" in
  65.         no)
  66.             break
  67.             ;;
  68.         esac
  69.     fi
  70.     done
  71. done
  72. if $found
  73. then
  74.     exit 0
  75. else
  76.     exit 1
  77. fi
  78.